<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" :rules="rules">
      <el-form-item label="区县代码" prop="qy">
        <el-select v-model="queryParams.qy" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in qyList"
            :key="dict.v"
            :label="dict.n"
            :value="dict.v"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="学校" prop="zxmc">
        <el-select v-model="queryParams.zxmc" placeholder="请选择" clearable filterable size="small">
          <el-option
            v-for="dict in zxmcList"
            :key="dict.zxmc"
            :label="dict.zxmc"
            :value="dict.zxmc"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="bjdm">
        <el-select v-model="queryParams.bjdm" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in bjdmList"
            :key="dict.bjdm"
            :label="dict.bjdm"
            :value="dict.bjdm"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="准考号" prop="zkh">
        <el-input
          v-model="queryParams.zkh"
          placeholder="请输入准考证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建档号" prop="jdh">
        <el-input
          v-model="queryParams.jdh"
          placeholder="请输入建档号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in dict.type.candidate_process_status "
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.startTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.endTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handlePrint"
          v-hasPermi="['business:examSummaryResults:print']"
        >打印
        </el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          :loading="exportLoading"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:examSummaryResults:export2']"-->
<!--        >导出-->
<!--        </el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="resultList">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + (queryParams.pageNo - 1) * queryParams.pageSize + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="准考号" align="center" prop="zkz"/>
      <el-table-column label="姓名" align="center" prop="ksName"/>
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="必考项" align="center" prop="bctyxmName" width="110px"/>
      <el-table-column label="必考状态" align="center" prop="bctyxmStatus">
        <template slot-scope="scope">
          <span>{{
              returnExamInfo(scope.row.bctyxmName, scope.row.bctyxmResult, scope.row.bctyxmStatus, scope.row.bctyxmValue)
            }}</span>
        </template>
      </el-table-column>
      <el-table-column label="选考项1" align="center" prop="xctyxm1Name"/>
      <el-table-column label="选考1状态" align="center" prop="xctyxm1Status">
        <template slot-scope="scope">
          <span>{{
              returnExamInfo(scope.row.xctyxm1Name, scope.row.xctyxm1Result, scope.row.xctyxm1Status, scope.row.xctyxm1Value)
            }}</span>
        </template>
      </el-table-column>
      <el-table-column label="选考项2" align="center" prop="xctyxm2Name"/>
      <el-table-column label="选考2状态" align="center" prop="xctyxm2Status">
        <template slot-scope="scope">
          <span>{{
              returnExamInfo(scope.row.xctyxm2Name, scope.row.xctyxm2Result, scope.row.xctyxm2Status, scope.row.xctyxm2Value)
            }}</span>
        </template>
      </el-table-column>
      <el-table-column label="考试状态" align="center" prop="kszt">
        <template slot-scope="scope">
          <span>{{ returnStatus(scope.row) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="qkzt"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { exportResult, exportResult2, listResult, print2 } from '@/api/business/examSummaryResult/examSummaryResult'
import { examProjectsList, schoolClass, schools } from '@/api/business/candidate/candidate'
import { getSuZhouQuYu } from '@/api/business/school/school'
import { listSchool } from '@/api/business/school/school'
import { printExcel } from '@/api/system/pointExcel'
import { printExcel1 } from '@/api/system/pointExcel1'

export default {
  name: 'Result',
  dicts: ['sys_user_sex', 'candidate_process_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考生考试项目汇总成绩表格数据
      resultList: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        qy: null,
        zxmc: null,
        bjdm: null,
        zkh: null,
        jdh: null,
        status: null,
        startTime: null,
        endTime: null
      },
      zxmcList: [],
      //区域列表
      qyList: [],
      bjdmList: [],
      projectIdList: [],
      form: {},
      // 表单校验
      rules: {
        zkh: [
          { pattern: /^[0-9]+$/, message: '准考号只能输入数字' }
        ]
      },
    }
  },
  created() {
    this.getList()
    listSchool().then(response => {
      this.zxmcList = response.rows
    })
    schoolClass().then(response => {
      this.bjdmList = response.data
    })
    examProjectsList().then(response => {
      this.projectIdList = response.data
    })
    getSuZhouQuYu().then(response => {
      this.qyList = response.data
    })
  },
  methods: {
    /** 查询考生考试项目汇总成绩列表 */
    getList() {
      this.loading = true
      listResult(this.queryParams).then(response => {
        this.resultList = response.data.records
        this.total = response.data.totalCount
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    //打印
    handlePrint() {
      this.loading = true
      print2(this.queryParams).then(response => {
        console.log(response.data)
        this.loading = false
        let tableDiv = '<table>' +
          '<tr>' +
          '<th>序号</th>' +
          '<th>准考号</th>' +
          '<th>姓名</th>' +
          '<th>性别</th>' +
          '<th>必考项</th>' +
          '<th>必考状态</th>' +
          '<th>选考项1</th>' +
          '<th>选考1状态</th>' +
          '<th>选考项2</th>' +
          '<th>选考2状态</th>' +
          '</tr>'
        for (let i = 0; i < response.data.length; i++) {
          let tr1 = '<tr>' +
            '<td>' + (i+1) + '</td>' +
            '<td>' + response.data[i].zkz + '</td>' +
            '<td>' + response.data[i].ksName + '</td>' +
            '<td>' + response.data[i].genderStr + '</td>' +
            '<td>' + response.data[i].bkx + '</td>' +
            '<td>' + response.data[i].bkxStr + '</td>' +
            '<td>' + response.data[i].xkx1 + '</td>' +
            '<td>' + response.data[i].xkx1Str + '</td>' +
            '<td>' + response.data[i].xkx2Name + '</td>' +
            '<td>' + response.data[i].xkx2Str + '</td>' +
            '</tr>'
          tableDiv += tr1
        }
        tableDiv += '</table>'
        printExcel1(tableDiv)
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$modal.confirm('是否确认导出所有考生考试项目汇总成绩数据项？').then(() => {
        this.exportLoading = true
        return exportResult2(queryParams)
      }).then(response => {
        this.$download.name(response.msg)
        this.exportLoading = false
      }).catch(() => {
      })
    },
    //考试状态
    returnStatus(row) {
      if (row.bctyxmStatus === '未考' || row.xctyxm1Status === '未考' || row.xctyxm2Status === '未考' ||
        row.bctyxmStatus === '缓考' || row.xctyxm1Status === '缓考' || row.xctyxm2Status === '缓考' ||
        row.bctyxmStatus === '重考' || row.xctyxm1Status === '重考' || row.xctyxm2Status === '重考') {
        return '未考完'
      }
      return '已考三项'
    },
    returnExamInfo(name, result, status, value) {
      if (status === '缓考' || status === '未考' || status === '重考') {
        return status
      }
      if (status === '设备' || status === '人工' || status === '修改成绩') {
        return ' 已考 - ' + value + '分' + ' - ' + result
      }
      if (name == null) {
        return '-'
      }
      return status + ' - ' + value + '分'
    }
  }
}
</script>
